﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Fraction.Test
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void FractionCtorTest()
        {
            // Arrange

            // Act
            var f = new Fraction();
            // Assert
            Assert.AreEqual(0, f.Numerator);
        }

        [TestMethod]
        public void FractionCtorTest2()
        {
            // Arrange

            // Act
            var f = new Fraction(4);
            // Assert
            Assert.AreEqual(4, f.Numerator);
            Assert.AreEqual(1, f.Denominator);
        }

        [TestMethod]
        [ExpectedException(typeof(ZeroDenominatorException))]
        public void FractionCtorExceptionTest()
        {
            // Arrange

            // Act
            try
            {
                var f = new Fraction(0, 0);
            }
            catch (ZeroDenominatorException e)
            {
                throw;
            }
            // Assert
        }
        [TestMethod]
        public void FractionNegationTest()
        {
            // Arrange
            var f = new Fraction(1, 2);
            // Act
            var f2 = -f;
            // Assert
            Assert.AreEqual(f.Numerator, -f2.Numerator);
        }

        [TestMethod]
        public void FractionReciprocalTest()
        {
            // Arrange
            var f = new Fraction(11, 21);
            // Act
            var f2 = ~f;
            // Assert
            Assert.AreEqual(21, f2.Numerator);
            Assert.AreEqual(11, f2.Denominator);
        }

        [TestMethod]
        public void FractionDecTest()
        {
            // Arrange
            var f = new Fraction(3, 2);
            var f2 = new Fraction(3, 2);
            // Act
            // Assert
            Assert.IsTrue(f2 == f--);
        }

        [TestMethod]
        public void FractionDecTest2()
        {
            // Arrange
            var f = new Fraction(3, 2);
            var f2 = new Fraction(1, 2);

            // Act
            // Assert
            Assert.IsTrue(f2 == --f);
        }
    }
}
